package com.maven.front.service.manageArticle;

import com.maven.front.bean.EduArticle;
import com.maven.front.bean.EduArticleContent;
import com.maven.front.bean.Result;
import com.maven.front.dto.EduArticleDto;
import com.maven.front.mapper.EduArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//添加文章模块
@Service
public class AddArticleService {
    @Autowired
    private EduArticleMapper eduArticleMapper;
    public int save(EduArticleDto eduArticleDto){
        int res=eduArticleMapper.insertSelective(eduArticleDto);
        int id=eduArticleDto.getArticleId();
      String content=eduArticleDto.getContent();
        System.out.println(id+"****************************");
        System.out.println(content+"****************************");
        EduArticleContent ec=new EduArticleContent();
        ec.setArticleId(id);
        ec.setContent(content);


        //return 1 表示两张表同时新增成功
        //return 0 表示EduArticleContent表新增失败
        //return -1 表示eduArticleDto表新增失败
        if(res>0){
            System.out.println(ec.getArticleId()+"*********************************");
            System.out.println(ec.getContent()+"*********************************");
          int value=eduArticleMapper.saveArticleController(ec);
            if(value>0){
                return  1;
            }
            return 0;
        }

        return 0;
    }



}
